package com.bjesc_b2c.app.appraiset.mvp.view.activity;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.bjesc_b2c.app.appraiset.R;
import com.bjesc_b2c.app.appraiset.adapter.DemandCarAdapter;
import com.bjesc_b2c.app.appraiset.base.BaseActivity;
import com.bjesc_b2c.app.appraiset.mvp.presenter.LikeCarPresenter;
import com.bjesc_b2c.app.appraiset.mvp.presenter.impl.LikeCarPresenterImpl;
import com.bjesc_b2c.app.appraiset.mvp.view.LikeCarView;
import com.bjesc_b2c.app.appraiset.utils.CustomSharedPreferences;
import com.bjesc_b2c.app.appraiset.widget.popupwindow.FilterCarPop;
import com.liaoinstan.springview.container.DefaultFooter;
import com.liaoinstan.springview.widget.SpringView;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;
import master_bean.DemandCarBean;
import master_bean.FindCarBean;
import rxretrofit_base.model.KeyBean;

/**
 * Created by yidong on 2017/5/25.
 */

public class LikeDealersActivity extends BaseActivity implements SpringView.OnFreshListener,LikeCarView {

    @InjectView(R.id.recycler_view)
    RecyclerView recyclerView;
    @InjectView(R.id.spring_view)
    SpringView springView;
    @InjectView(R.id.tv_title)
    TextView titleTV;
    @InjectView(R.id.view_title)
    View titleview;

    private List<DemandCarBean> datas;
    private LikeCarPresenter presenter;
    private FindCarBean findCarBean;
    private DemandCarAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_demand_car);
        ButterKnife.inject(this);
        String touid = CustomSharedPreferences.getString(this, KeyBean.TOU_ID.valueOf(),KeyBean.FILE_NAME.valueOf());
        titleTV.setText("相似车源");
        findCarBean = new FindCarBean();
        findCarBean.setTou_id(touid);
        presenter = new LikeCarPresenterImpl(this);
        presenter.getLikeCars(findCarBean);
        initViews();
    }
    private void initViews() {
        springView.setListener(this);
        springView.setHeader(new DefaultFooter(this));
        springView.setFooter(new DefaultFooter(this));
        springView.setType(SpringView.Type.FOLLOW);
        LinearLayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
        recyclerView.setLayoutManager(layoutManager);

    }
    @Override
    protected void onStart() {
        super.onStart();
    }

    @Override
    public void getLikeCars(List<DemandCarBean> datas) {
        adapter = new DemandCarAdapter(LikeDealersActivity.this,R.layout.layout_item_demand_car,datas);
        recyclerView.setAdapter(adapter);
    }

    @OnClick({R.id.iv_return,R.id.tv_filter,R.id.btn_determine,R.id.btn_cancel})
    public void onClick(View view){
        switch (view.getId()){
            case R.id.iv_return:
                finish();
                break;
            case R.id.tv_filter://筛选
                FilterCarPop filterCarPop = new FilterCarPop(LikeDealersActivity.this,null);
                filterCarPop.showAsDropDown(titleview);
                break;
            case R.id.btn_determine:
                break;
            case R.id.btn_cancel:
                break;
        }

    }

    @Override
    public void onRefresh() {

    }

    @Override
    public void onLoadmore() {

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
